import java.util.*;

/**
 * @author LKQ
 * @date 2022/3/9 14:21
 * @description 不用map，用数组
 */
public class Solution2 {
    public static void main(String[] args) {

    }
    public List<String> wordSubsets(String[] words1, String[] words2) {
        int[] max = new int[26];
        for (String word: words2) {
            int[] temp = count(word);
            for (int i = 0; i < 26; i++) {
                max[i] = Math.max(max[i], temp[i]);
            }
        }
        List<String> ans = new ArrayList<>();
        for (String word: words1) {
            int[] cur = count(word);
            boolean fit = true;
            for (int i = 0; i < 26; i++) {
                if (max[i] > cur[i]) {
                    fit = false;
                    break;
                }
            }
            if (fit) {
                ans.add(word);
            }
        }
        return ans;
    }
    public int[] count(String s) {
        int[] ans = new int[26];
        for (char ch: s.toCharArray()) {
            ans[ch-'a']++;
        }
        return ans;
    }
}
